package com.mql.ganio.ui.fragment;

import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.view.View;

import com.mql.ganio.R;
import com.mql.ganio.ui.adapter.CommonFragmentPagerAdapter;
import com.mql.ganio.ui.base.BaseFragment;
import com.mql.ganio.ui.base.BasePresenter;

import java.util.ArrayList;

import butterknife.Bind;

/**
 * @创建者 mql
 * @描述 干货fragment
 */
public class GanIoFragment extends BaseFragment {
    @Bind(R.id.tab_gank)
    TabLayout mTabGank;
    @Bind(R.id.vp_gank)
    ViewPager mVpGank;
    private ArrayList<String> mTitleList;
    private ArrayList<BaseFragment> mFragments;

    @Override
    protected BasePresenter createPresenter() {
        return null;
    }

    @Override
    public void init() {
        super.init();
        initFragmentList();

    }

    @Override
    public void initView(View rootView) {
        super.initView(rootView);
        CommonFragmentPagerAdapter myAdapter = new CommonFragmentPagerAdapter(getChildFragmentManager(), mFragments, mTitleList);
        mVpGank.setAdapter(myAdapter);
        // 左右预加载页面的个数
        mVpGank.setOffscreenPageLimit(2);
        myAdapter.notifyDataSetChanged();
        mTabGank.setTabMode(TabLayout.MODE_FIXED);
        mTabGank.setupWithViewPager(mVpGank);

    }

    private void initFragmentList() {
        mTitleList = new ArrayList<>(3);
        mFragments = new ArrayList<>(3);
        mTitleList.add("每日推荐");
        mTitleList.add("干货订制");
        mTitleList.add("大安卓");
        mFragments.add(new EverydayFragment());
        mFragments.add(new CustomFragment());
        mFragments.add(new AndroidFragment());
    }

    @Override
    protected int provideContentViewId() {
        return R.layout.fragment_ganhuo;
    }


}
